//
//  RCConsumeCell.m
//  RocketProject
//
//  Created by chen jiedan on 13-7-2.
//  Copyright (c) 2013年 Rocket. All rights reserved.
//

#import "RCConsumeCell.h"
#import "CommonDefines.h"
#import "UIColor-Expanded.h"
#import "TTTAttributedLabel.h"
#import "NSAttributedString+LVAddition.h"

#define kTextBGImageFile             @"image_about_textBG.png"



@implementation RCConsumeCell{
    
    UIImageView *_bgImageView;
    UILabel *_merchantLabel;
    UILabel *_merchantName;
    UILabel *_statusLabel;
    UILabel *_orderLabel;
    UILabel *_orderName;
    UILabel *_phoneLabel;
    UILabel *_orderTimeLabel;
    UILabel *_orderTime;
    UILabel *_extraLabel;
    TTTAttributedLabel *_extraInfoLabel;
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        [self setUpView];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}


- (void) setUpView
{
    
    NSString *resourcePath = [[NSBundle mainBundle]resourcePath];
    NSString *textBGFilePath = [resourcePath stringByAppendingPathComponent:kTextBGImageFile];
    UIImage *textBGImage = [UIImage imageWithContentsOfFile:textBGFilePath];
    textBGImage = [textBGImage resizableImageWithCapInsets:UIEdgeInsetsMake(5, 5, 5, 5)];
    
    _bgImageView = [[UIImageView alloc] initWithFrame:CGRectMake(13, 11, 294, 58)];
    [_bgImageView setImage:textBGImage];
    
    _merchantLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 50, 12)];
    _merchantLabel.backgroundColor = [UIColor clearColor];
    _merchantLabel.font = [UIFont fontWithName:kFontNameLightHeiti size:12];
    _merchantLabel.textColor = [UIColor colorWithHex:0xff767676];
    _merchantLabel.text = @"店铺名称";
    [_bgImageView addSubview:_merchantLabel];
    [_merchantLabel release];
    
    _merchantName = [[UILabel alloc] initWithFrame:CGRectMake(65, 10, 170, 12)];
    _merchantName.backgroundColor = [UIColor clearColor];
    _merchantName.font = [UIFont fontWithName:kFontNameLightHeiti size:12];
    _merchantName.textColor = [UIColor colorWithHex:0xff010101];
    [_bgImageView addSubview:_merchantName];
    [_merchantName release];
    
    _statusLabel = [[UILabel alloc] initWithFrame:CGRectMake(240, 10, 54, 12)];
    _statusLabel.backgroundColor = [UIColor clearColor];
    _statusLabel.font = [UIFont fontWithName:kFontNameLightHeiti size:12];
    _statusLabel.textColor = [UIColor colorWithHex:0xffff7e00];
    [_bgImageView addSubview:_statusLabel];
    [_statusLabel release];
    
    _orderLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 32, 50, 12)];
    _orderLabel.backgroundColor = [UIColor clearColor];
    _orderLabel.font = [UIFont fontWithName:kFontNameLightHeiti size:12];
    _orderLabel.textColor = [UIColor colorWithHex:0xff767676];
    _orderLabel.text = @"预订人";
    [_bgImageView addSubview:_orderLabel];
    [_orderLabel release];
    
    _orderName = [[UILabel alloc] initWithFrame:CGRectMake(65, 32, 200, 12)];
    _orderName.backgroundColor = [UIColor clearColor];
    _orderName.font = [UIFont fontWithName:kFontNameLightHeiti size:12];
    _orderName.textColor = [UIColor colorWithHex:0xff010101];
    [_bgImageView addSubview:_orderName];
    [_orderName release];
    
    _phoneLabel = [[UILabel alloc] initWithFrame:CGRectMake(210, 32, 79, 12)];
    _phoneLabel.backgroundColor = [UIColor clearColor];
    _phoneLabel.font = [UIFont fontWithName:kFontNameLightHeiti size:12];
    _phoneLabel.textAlignment = UITextAlignmentRight;
    _phoneLabel.textColor = [UIColor colorWithHex:0xff585858];
    [_bgImageView addSubview:_phoneLabel];
    [_phoneLabel release];
    
    _orderTimeLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 54, 50, 12)];
    _orderTimeLabel.backgroundColor = [UIColor clearColor];
    _orderTimeLabel.font = [UIFont fontWithName:kFontNameLightHeiti size:12];
    _orderTimeLabel.textColor = [UIColor colorWithHex:0xff767676];
    _orderTimeLabel.text = @"预订时间";
    [_bgImageView addSubview:_orderTimeLabel];
    [_orderTimeLabel release];
    
    _orderTime = [[UILabel alloc] initWithFrame:CGRectMake(65, 54, 200, 12)];
    _orderTime.backgroundColor = [UIColor clearColor];
    _orderTime.font = [UIFont fontWithName:kFontNameLightHeiti size:12];
    _orderTime.textColor = [UIColor colorWithHex:0xff010101];
    [_bgImageView addSubview:_orderTime];
    [_orderTime release];
    
    _extraLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 76, 50, 12)];
    _extraLabel.backgroundColor = [UIColor clearColor];
    _extraLabel.font = [UIFont fontWithName:kFontNameLightHeiti size:12];
    _extraLabel.textColor = [UIColor colorWithHex:0xff767676];
    _extraLabel.text = @"备注";
    [_bgImageView addSubview:_extraLabel];
    [_extraLabel release];
    
    _extraInfoLabel = [[TTTAttributedLabel alloc]initWithFrame:CGRectMake(65, 76, 219, 100)];
    _extraInfoLabel.backgroundColor = [UIColor clearColor];
    _extraInfoLabel.textColor = [UIColor colorWithHex:0xff010101];
    _extraInfoLabel.font = [UIFont fontWithName:kFontNameLightHeiti size:12];
    _extraInfoLabel.numberOfLines = 0;
    _extraInfoLabel.leading = 6;
    [_bgImageView addSubview:_extraInfoLabel];
    [_extraInfoLabel release];
    
    [self.contentView addSubview:_bgImageView];
    [_bgImageView release];
}

- (void) bindData:(RCCostItemDataModel *)data
{
    if (nil == data) {
        return;
    }
    _merchantName.text = data.consume_addr;
    _statusLabel.text = data.consume_state;
    _orderName.text = data.consume_name;
    _phoneLabel.text = data.consume_phone;
    _orderTime.text = data.consume_date;
    
    _extraInfoLabel.text = data.consume_extra;
    NSAttributedString *attributedStr = _extraInfoLabel.attributedText;
    CGSize size = [attributedStr sizeWithConstrainedToSize:CGSizeMake(219, 2000) Leading:6];
    _extraInfoLabel.frame = CGRectMake(55, 76, 219, size.height);
    
    _bgImageView.frame = CGRectMake(13, 11, 294, 76+size.height +10);
}

+(CGFloat)getCellHeight:(RCCostItemDataModel *)data{
    if (nil == data) {
        return 0;
    }
    
    TTTAttributedLabel *label = [[TTTAttributedLabel alloc]initWithFrame:CGRectMake(55, 76, 219, 100)];
    label.backgroundColor = [UIColor clearColor];
    label.textColor = [UIColor colorWithHex:0xff010101];
    label.font = [UIFont fontWithName:kFontNameLightHeiti size:12];
    label.numberOfLines = 0;
    label.leading = 6;
    label.text = data.consume_extra;
    NSAttributedString *attributedStr = label.attributedText;
    CGSize size = [attributedStr sizeWithConstrainedToSize:CGSizeMake(219, 2000) Leading:6];
    [label release];
    
    return 13+86+size.height;
}
@end
